package com.pengshun.modules.api.news.controller;

import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.news.service.NewsService;
import com.pengshun.modules.api.news.service.dto.NewsDto;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/1/20
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "新闻管理")
@RequestMapping("/api/news")
public class NewsController {

    private final NewsService newsService;

    @ApiOperation(value = "新闻列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "类别id ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页从0开始 ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数 ", dataType = "int", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    public BaseResult getOrderListByStatus( @ApiIgnore @Validated(value = {Fourth.class}) PagePara dto) throws Exception {
        BaseResult res = newsService.getOrderListByStatus(dto);
        return res;

    }
    @ApiOperation(value = "首页头条轮播")
    @GetMapping(value = "/home")
    public BaseResult getHomeList() throws Exception {
        BaseResult res = newsService.getHomeList();
        return res;

    }
    @ApiOperation(value = "新闻詳情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "newId", value = "新闻id ", dataType = "int", required = true, paramType = "query"),
    })
    @GetMapping(value = "/detil")
    public BaseResult getNewsDetil( @ApiIgnore @Validated(value = {Fourth.class}) NewsDto dto) throws Exception {
        BaseResult res = newsService.getNewsDetil(dto.getNewId());
        return res;

    }
}
